package com.nowcode.community.utils;

import com.nowcode.community.entity.User;
import org.springframework.stereotype.Component;

/**
 * ClassName: HoatHolder
 * Package: com.nowcode.community.utils
 * Description:
 *
 * @Author: 信
 * @Create: 2024/1/23 - 9:55
 */
//TODO 11、容器作用，持有用户信息，用于代替session对象  ，使用ThreadLocal
@Component
public class HostHolder {

    private ThreadLocal<User> users = new ThreadLocal<>();

    public void setUser(User user) {
        users.set(user);
    }

    public User getUser() {
        return users.get();
    }

    public void clear() {
        users.remove();
    }

}
